#include <bits/stdc++.h>

template<typename T1, typename T2>
std::ostream &operator<<(std::ostream &os, std::pair<T1, T2> obj) {
  return os << obj.first << ' ' << obj.second;
}

namespace Tools {
  long long Solve(const std::vector<long long> &arr) {
    assert(std::is_sorted(arr.begin(), arr.end()));
    int N = (int) arr.size();
    long long res = 0, pR = 0, cL = 0, cR = 0;
    bool flag = false;
    for (int i = 0; i < N; i++) {
      cL += arr[i], cR += arr[N - i - 1];
      if (!flag && i && pR <= cL) { res += pR - arr[0], flag = true; }
      if (flag) { assert(pR <= cL); }
      if (flag) { res += cR - cL; }
      pR = cR;
    }
    return res;
  }
}

namespace Force {
  auto Solve(const std::vector<long long> &qur) {
    std::vector<long long> arr, ret;
    for (auto x: qur) {
      auto it = std::lower_bound(arr.begin(), arr.end(), x);
      if (it == arr.end() || *it != x) {
        arr.insert(it, x);
      } else {
        arr.erase(it);
      }
      ret.emplace_back(Tools::Solve(arr));
    }
    return ret;
  }
}

class SegmentTree {
  struct Node {
    int cnt;
    long long sum, tag;

    void push(long long x) {
      sum += cnt * x, tag += x;
    }
  };

  int N;
  std::vector<Node> tree;

#define T(u) tree[u]
#define LS(u) (u << 1)
#define RS(u) (u << 1 | 1)

  void PushUp(int u) {
    T(u).sum = T(LS(u)).sum + T(RS(u)).sum;
  }

  void PushDown(int u) {
    if (T(u).tag) {
      T(LS(u)).push(T(u).tag);
      T(RS(u)).push(T(u).tag);
      T(u).tag = 0;
    }
  }

  void Insert(int x, int v, int u, int L, int R) {
    if (R <= x || x < L) { return; }
    T(u).cnt += v;
    if (L + 1 == R) { return T(u).sum = T(u).tag * T(u).cnt, void(); }
    PushDown(u);
    int M = (L + R) >> 1;
    Insert(x, v, LS(u), L, M);
    Insert(x, v, RS(u), M, R);
    PushUp(u);
  }

  void Modify(int l, int r, long long v, int u, int L, int R) {
    if (R <= l || r <= L) { return; }
    if (l <= L && R <= r) { return T(u).push(v); }
    PushDown(u);
    int M = (L + R) >> 1;
    Modify(l, r, v, LS(u), L, M);
    Modify(l, r, v, RS(u), M, R);
    PushUp(u);
  }

  long long Query(int l, int r, int u, int L, int R) {
    if (R <= l || r <= L) { return 0; } 
    if (l <= L && R <= r) { return T(u).sum; }
    PushDown(u);
    int M = (L + R) >> 1;
    return Query(l, r, LS(u), L, M) + Query(l, r, RS(u), M, R);
  }

  std::pair<long long, int> Kth(int k, int u, int L, int R) {
    if (L + 1 == R) { return std::make_pair(T(u).sum, L); }
    PushDown(u);
    int M = (L + R) >> 1;
    if (k <= T(LS(u)).cnt) { return Kth(k, LS(u), L, M); }
    return Kth(k - T(LS(u)).cnt, RS(u), M, R);
  }

public:
  explicit SegmentTree(int N) : N(N) { tree.resize(4 * N); }

  void insert(int x, int v) { Insert(x, v, 1, 0, N); }

  void modify(int l, int r, long long v) { Modify(l, r + 1, v, 1, 0, N); }

  long long query(int l, int r) { return Query(l, r + 1, 1, 0, N); }

  auto kth(int k) { return Kth(k, 1, 0, N); }

  int size() const { return T(1).cnt; }
};

namespace Solution {
  auto Solve(const std::vector<long long> &qur) {
    auto disc = qur;
    std::sort(disc.begin(), disc.end());
    disc.erase(std::unique(disc.begin(), disc.end()), disc.end());
    int N = (int) disc.size();

    std::vector<int> vis(N);
    std::vector<long long> ret;
    SegmentTree sgt1(N), sgt2(N);

    for (auto v: qur) {
      int p = std::lower_bound(disc.begin(), disc.end(), v) - disc.begin();
      int o = (vis[p] ^= 1) ? 1 : -1;

      sgt1.insert(p, o), sgt1.modify(p, N - 1, v * o);
      p = N - 1 - p;
      sgt2.insert(p, o), sgt2.modify(p, N - 1, v * o);

      int L = 1, R = sgt1.size() - 1;
      while (L < R) {
        int M = (L + R) >> 1;
        if (sgt1.kth(M + 1).first >= sgt2.kth(M).first) {
          R = M;
        } else {
          L = M + 1;
        }
      }
      long long res = sgt2.kth(L).first - sgt1.kth(1).first;
      res += sgt2.query(sgt2.kth(L + 1).second, N - 1);
      res -= sgt1.query(sgt1.kth(L + 1).second, N - 1);
      ret.emplace_back(res);
    }

    return ret;
  }
}

int main() {
  freopen("kte.in", "r", stdin);
  freopen("kte.out", "w", stdout);
  freopen("kte.err", "w", stderr);
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int Q;
  std::cin >> Q;
  std::vector<long long> qur(Q), ans;
  for (auto &v: qur) { std::cin >> v; }

  if (Q <= 2000) {
    ans = Force::Solve(qur);
  } else {
    ans = Solution::Solve(qur);
  }

  for (auto v: ans) { std::cout << v << '\n'; }
  std::cerr << clock() << '\n';

  return 0;
}